/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import entities.Artwork;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;



/**
 *
 * @author bertram
 */
public class SearchProvider {

    private PostGres pg = PostGres.getInstance();

    public SearchProvider() {
    }

    public ArrayList<Integer> searchWorksByTitle(String title) {
        DataProvider prov = new DataProvider();
        ArrayList<Integer> Ids = new ArrayList<Integer>();
        try {
            Connection conn = pg.getConnection();
            String sql = "SELECT vaerk_id from kunstdeling.kunstvaerk where kunstvaerk.titel ilike ?";
            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.setString(1, "%"+title+"%");
            ResultSet res = stmt.executeQuery();
            if(!res.isBeforeFirst())//hvis ingen resultater
            {
                System.out.println("empty stmt");
                conn.close();
                return Ids;
            }
            while(res.next())
            {
                 System.out.println("en mere");
                int workID = res.getInt("vaerk_id");
                Ids.add(workID);
               
            }
            conn.close();
            System.out.println("happy bughunting");
            return Ids;
           


        } catch (SQLException ex) {
           System.out.println("kunne ikke få søge forbindelse" + ex.getMessage());
        }

        return Ids;
    }
}
